package org.xjtu.weteam.model.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;
import org.springframework.format.annotation.DateTimeFormat;
import org.xjtu.weteam.model.dto.ProjectDateDTO;

import java.sql.Date;
import java.sql.Timestamp;

/**
 * @author Kevin
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@Entity
@Table(name = "Project")
public class Project {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer projectId;
    private Integer teamId;
    private Integer userId;
    private String projectName;
    private String description;
    private Date startDate;
    private Date endDate;

    private String status;

    @ManyToOne
    @JoinColumn(name = "status", referencedColumnName = "code", insertable = false, updatable = false)
    private Dictionary statusDictionary; // 关联 Dictionary 实体

    private String url;

    @Column(name = "createTime", updatable = false)
    private Timestamp createTime;

    @Column(name = "updateTime")
    private Timestamp updateTime;

    public Project(ProjectDateDTO projectDateDTO){
        BeanUtils.copyProperties( projectDateDTO, this);
        Date start = java.sql.Date.valueOf(projectDateDTO.getStartDate());
        setStartDate(start);
        Date end = java.sql.Date.valueOf(projectDateDTO.getEndDate());
        setEndDate(end);
    }
}
